#include "inc.h"

int main(int argc, char const *argv[])
{
    printf("main pid = %d\n", getpid());

    int iCounter = 0;

    pid_t pid = fork();

    if( pid > 0 )
    {
        while(1)
        {
/*            printf("----This is Father Proccess----\n");
            printf("    forked pid = %d,   self pid = %d, father pid = %d\n",
                    pid, getpid(), getppid());*/
            printf("Father iCounter %d\n", iCounter++ );
            sleep(2);
        }

    }
    else if ( 0 == pid )
    {
        while(1)
        {
 /*           printf("----This is Son    Proccess----\n");
            printf("    self   pid = %d, father pid = %d\n", getpid(), getppid()); */
            printf("Son    iCounter %d\n", iCounter++ );
            sleep(2);
        }
       
    }
    else
    {
        perror("fail fork");
        return -1;
    }

    return 0;
    
}

/*
程序功能
    创建一个子进程, 父子进程各自无限循环打印信息.

涉及函数
    fork

知识要点
    子进程启动之后, 系统随机调用进程
    两个进程各自有一个无限循环
    进程有自己独立的 4G 虚拟内存空间
*/
